import java.util.Random;


public class Customer extends Thread{
	

	public static long time = MY_PLACE.time;
	protected static final int SHOP_TIME_MAX = 5000;
	public int customerId = 0;	
	public String paymentType;
	private static int customerCount = 0;
	
	public Customer() {
		customerCount++;
		customerId = customerCount;
		setName("Customer- C" + customerCount);
	}

	public void msg(String m) {
		System.out.println("["+(System.currentTimeMillis()-time)+"] "+getName()+": "+m);
	}
	
	public void run(){
		msg("A Customer Thread has Started Running (Customer #"+ customerId + ")");
		shop();
		getSlip();
		pay();
		yield();
		msg("Done paying. Going to cafeteria");
		takeBreak();
	}

	private void shop() {
		int randomNum;
		randomNum = 500 + (int)(Math.random() * (SHOP_TIME_MAX - 500));
		try {
			sleep(randomNum);
			msg("Done shopping. Going to floor clerk");
		} catch (InterruptedException e) {
		}		
	}

	private void getSlip() {
		// TODO Auto-generated method stub
		
	}

	public void pay() {
		this.raisePriority();
		this.setPaymentType();
		msg("Has arrived at the cashier cue to pay with " + paymentType);
//		this.setPriority(Thread.NORM_PRIORITY);
//		msg("Truck #" + truckId + " Has arrived at factory with a "+partType);
//		MY_PLACE.Cash_Cashier.customerQue.addElement(this);		
		MY_PLACE.acceptCustomer(this);
//		Factory.truckQue.addElement(this);		
	}

	private void takeBreak() {
		Thread.yield();
		
	}

	public void raisePriority() {
		int higherPriority;
		if ((this.getPriority()+3)>10)
			higherPriority = 10;
		else higherPriority = this.getPriority()+3;
		
		this.setPriority(higherPriority);		
	}

	public String getPaymentType (){
		return paymentType;
	}

	public void setPaymentType(){
	    Random random = new Random();
	    boolean p = random.nextBoolean();
	    if (p == true)
	    	paymentType = "CASH";
	    else
	    	paymentType = "CREDIT CARD";
	}

	public String toString(){
		return("Customer #"+customerId+" ; Payment = " + paymentType);
	}
}

/*

public static long time = Scarecrow_Factory.time;
public int customerId = 0;	
public int deliveryAttempts = 0;
public String paymentType;
public boolean partIsSurplus = false;
public boolean truckReturned = false;
private static int customerCount = 0;

public Truck() {
	customerCount++;
	customerId = customerCount;
	setName("Truck- T" + customerCount);
}

public void msg(String m) {
	System.out.println("["+(System.currentTimeMillis()-time)+"] "+getName()+": "+m);
}

public void run(){
	msg("A Truck Thread has Started Running (truck #"+ customerId + ")");

*/